package com.bupt.basic;

import com.bupt.entity.Route;
import com.bupt.exception.BaseException;

import com.bupt.utils.excel.ExcelField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 需求提报的业务
 *
 * @author breakpoint/赵先生
 * 2020/09/22
 */
@EqualsAndHashCode
@Data
public final class DemandReportService  implements Serializable {

    private static final long serialVersionUID = -5301577924356282548L;
    /*  基本信息  */
    private String id;// id
    @ExcelField(name = "业务名称")
    private String name; // name
    @ExcelField(name = "业务头节点", isExplored = false)
    private String nodeHead; // 开始节点
    @ExcelField(name = "开始位置", isExplored = true, isMouldColumn = false)
    private String nodeHeadName;
    @ExcelField(name = "业务尾节点", isExplored = false)
    private String nodeTail; // 结束节点
    @ExcelField(name = "结束位置", isExplored = true, isMouldColumn = false)
    private String nodeTailName;
    @ExcelField(name = "需求类型", selectValues = {"IP", "通信", "数据", "指挥", "视频"})
    private String type; // 需求类型
    @ExcelField(name = "需求带宽(单位：G)")
    private String bandwidth;  // 需求带宽
    private Double bandwidthNum; // 单位为G

    private String nodeMust; // 必经节点(/正则表示)

    private List<NodeMust> nodeMustArr=new ArrayList<>();

    private List<IBasicNetWork.Port> usePortList=new ArrayList<>();

    @Getter
    @Setter
    @Builder
    public static class NodeMust {
        private String nodeId;
        private String nodeName;
    }

    @ExcelField(name = "所属层级", selectValues = {"SDH", "OTN", "WDM"})
    private String layer; // 所属层级

    @ExcelField(name = "开通年份")
    private Integer year; // 建设年份

    @ExcelField(name = "业务保护等级(下拉选择)",
            selectValues = {"无保护", "1+1", "重路由", "1+1+重路由", "永久1+1"},
            isExplored = false, isMouldColumn = true)
    private String protect;

    @ExcelField(name = "业务保护等级", isMouldColumn = false)
    private String protectName;

   /* // # issue 转换的问题
    public void setProtect(String protect) throws BaseException {
        this.protect = getProtectByOri(protect);
        this.protectName = getProtectNameByOri(protect);
    }*/

    @ExcelField(name = "业务保护跳数（选填）")
    private Integer protectLimit;

    @JsonIgnore
    private Date gmtCreate;
    @JsonIgnore
    private String createUserId;
    @ExcelField(name = "创建人", isMouldColumn = false)
    private String createUserName;

    @ExcelField(name = "规划的状态", isMouldColumn = false)
    private String status = "未规划";

    // 规划的结果
    @ExcelField(name = "规划的结果", isMouldColumn = false, isWrapText = true)
    private String reason="未分配";

    @JsonIgnore
    private Route workRoute=new Route();// = new TbStrategyServiceImpl.Route();//工作路由
    @JsonIgnore
    private Route protectRoute=new Route();//保护路由

    @ExcelField(name="工作路由信息",isMouldColumn = false,isWrapText = true)
    private String workRouteMsg;//工作路由信息

    @ExcelField(name="保护路由信息",isMouldColumn = false,isWrapText = true)
    private String protectRouteMsg;//保护路由信息


    public void setBandwidth(String bandwidth) {
        this.bandwidth = bandwidth;
        // 设置速率
        this.bandwidthNum = Double.valueOf(bandwidth);
    }


    public DemandReportService() {
    }

    public DemandReportService(String id, String name, String nodeHead, String nodeTail, String type,
                               Double bandwidthNum, String nodeMust, String layer, Integer year, Date gmtCreate,
                               String createUserId, String createUserName) {
        this.id = id;
        this.name = name;
        this.nodeHead = nodeHead;
        this.nodeTail = nodeTail;
        this.type = type;
        this.bandwidthNum=bandwidthNum;
        this.nodeMust = nodeMust;
        this.layer = layer;
        this.year = year;
        this.gmtCreate = gmtCreate;
        this.createUserId = createUserId;
        this.createUserName = createUserName;
    }


    @JsonIgnore
    private Date gmtModified;
    @JsonIgnore
    private Boolean submit = false; // 是否被提报
    @JsonIgnore
    private String route; // 作废工作路由
    @JsonIgnore
    private String areaFrom; // 创建时所属军区
    @JsonIgnore
    private String areaTo; // 提交军区
    @JsonIgnore
    private String jbz;

    public void updateSelf(DemandReportService other) throws BaseException {
        this.name = other.name;
        this.nodeHead = other.nodeHead;
        this.nodeTail = other.nodeTail;
        // bugFix:#issue17 修改业务首节点之后重新规划，查看规划结果发现首节点未改变
        this.nodeHeadName = other.nodeHeadName;
        this.nodeTailName = other.nodeTailName;
        this.type = other.type;
        this.bandwidth = other.bandwidth;
        this.bandwidthNum = Double.valueOf(bandwidth);
        this.nodeMust = other.nodeMust;
        this.layer = other.layer;
        this.year = other.year;
        this.gmtModified = other.gmtModified;
        this.protectLimit = other.protectLimit;
    }
}
